//
//  BaseType.h
//  LotteryClient
//
//  Created by Sunyon 14-3-31.
//  Copyright (c) 2014年 CTTC. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef enum
{
	BaseTypeService = 1,
	BaseTypeBusiness = 2,
	BaseTypeViewController,
	BaseTypeEntity,
	BaseTypeResponse,
	BaseTypeRequest,
} BaseType;


#pragma mark - 单例模式 宏定义
#if __has_feature(objc_instancetype)

#undef	AS_SINGLETON
#define AS_SINGLETON

#undef	AS_SINGLETON
#define AS_SINGLETON( ... ) \
- (instancetype)sharedInstance; \
+ (instancetype)sharedInstance;

#undef	DEF_SINGLETON
#define DEF_SINGLETON \
- (instancetype)sharedInstance \
{ \
	return [[self class] sharedInstance]; \
} \
+ (instancetype)sharedInstance \
{ \
	static dispatch_once_t once; \
	static id __singleton__; \
	dispatch_once( &once, ^{ __singleton__ = [[self alloc] init]; } ); \
	return __singleton__; \
}

#undef	DEF_SINGLETON
#define DEF_SINGLETON( ... ) \
- (instancetype)sharedInstance \
{ \
	return [[self class] sharedInstance]; \
} \
+ (instancetype)sharedInstance \
{ \
	static dispatch_once_t once; \
	static id __singleton__; \
	dispatch_once( &once, ^{ __singleton__ = [[self alloc] init]; } ); \
	return __singleton__; \
}

#else	// #if __has_feature(objc_instancetype)

#undef	AS_SINGLETON
#define AS_SINGLETON( __class ) \
- (__class *)sharedInstance; \
+ (__class *)sharedInstance;

#undef	DEF_SINGLETON
#define DEF_SINGLETON( __class ) \
- (__class *)sharedInstance \
{ \
	return [__class sharedInstance]; \
} \
+ (__class *)sharedInstance \
{ \
	static dispatch_once_t once; \
	static __class * __singleton__; \
	dispatch_once( &once, ^{ __singleton__ = [[[self class] alloc] init]; } ); \
	return __singleton__; \
}

#endif	// #if __has_feature(objc_instancetype)


#pragma mark - 添加类常量

#undef	AS_STATIC_PROPERTY_INT
#define AS_STATIC_PROPERTY_INT( __name ) \
- (NSInteger)__name; \
+ (NSInteger)__name;

#undef	DEF_STATIC_PROPERTY_INT
#define DEF_STATIC_PROPERTY_INT( __name, __value ) \
- (NSInteger)__name \
{ \
	return (NSInteger)[[self class] __name]; \
} \
+ (NSInteger)__name \
{ \
	return __value; \
}

#undef	AS_STATIC_PROPERTY_NUMBER
#define AS_STATIC_PROPERTY_NUMBER( __name ) \
- (NSNumber *)__name; \
+ (NSNumber *)__name;

#undef	DEF_STATIC_PROPERTY_NUMBER
#define DEF_STATIC_PROPERTY_NUMBER( __name, __value ) \
- (NSNumber *)__name \
{ \
	return (NSNumber *)[[self class] __name]; \
} \
+ (NSNumber *)__name \
{ \
	return [NSNumber numberWithInt:__value]; \
}

#pragma mark -

#undef	AS_STATIC_PROPERTY_STRING
#define AS_STATIC_PROPERTY_STRING( __name ) \
- (NSString *)__name; \
+ (NSString *)__name;

#undef	DEF_STATIC_PROPERTY_STRING
#define DEF_STATIC_PROPERTY_STRING( __name, __value ) \
- (NSString *)__name \
{ \
	return [[self class] __name]; \
} \
+ (NSString *)__name \
{ \
	return __value; \
}


#undef	AS_CLASS_INSTANCE
#define AS_CLASS_INSTANCE(__class, __propertyName ) \
@property (nonatomic, strong) __class * __propertyName;

#undef	DEF_CLASS_INSTANCE
#define DEF_CLASS_INSTANCE( __class, __propertyName ) \
- (__class *)__propertyName \
{ \
if(!_##__propertyName)\
	{\
		if ([__class respondsToSelector:@selector(sharedInstance)])\
		{\
			_##__propertyName =[__class sharedInstance];\
		}\
		else\
		{\
			_##__propertyName =[[__class alloc] init];\
		}\
	}\
	return _##__propertyName;\
}\

#undef	RELEASE_INSTANCE
#define RELEASE_INSTANCE(__propertyName ) \
if(__propertyName)\
{\
	if (![[__propertyName class] respondsToSelector:@selector(sharedInstance)])\
	{\
        if(__propertyName)[__propertyName release]; __propertyName = nil;\
    }\
}





